@extends('app')
@section('content')
<ul class="nav nav-tabs">
    <li><a href="{{ url('/admin/bbs/top')}}">信息列表</a></li>
    <li class="active"><a href="#">信息编辑</a></li>
</ul>
<form id="newsForm" method="post" action="">
    <div class="panel panel-default description2">
        <div class="form-group clearfix">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label">选择帖子</label>
            <div class="col-sm-9 col-xs-12">
                <select name="question_id" class="form-control">
                    <option value="0">-----请选择帖子-----</option>
                    @foreach($questions as $qes)
                    <option value="{{$qes->id}}" @if(!empty($result)) @if($result->question_id == $qes->id) selected @endif @endif>{{$qes->title}}</option>
                    @endforeach
                </select>
            </div>
        </div>
        <div class="form-group clearfix">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label">帖子封面</label>
            <div class="col-sm-9 col-xs-12">
                <input id="uploadimg" name="uploadimg" type="file" multiple="true">
                <div id="imgbox" class="dustbin">
                    <div style='width:90px; height:60px;float:left;'>
                        <img src='@if(!empty($result)){{ $result->thumb }}@endif' /><input type='hidden' name='thumb' value='@if(!empty($result)){{ $result->thumb }}@endif' />
                    </div>
                </div>
                <div class="help-block">图片尺寸：390*250</div>
            </div>
        </div>
        <div class="form-group clearfix">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label">帖子简介</label>
            <div class="col-sm-9 col-xs-12">
               <textarea name="intro" id="intro" style="width:100%;height: 100px" >{{!empty($result)?$result->intro:''}}</textarea>
                <h6>你可以输入<span>140</span>个字，现在剩余<span id="word">140</span>个</h6>
                <script type="text/javascript">
                    $(function(){
                        $("#intro").keyup(function(){
                            var len = $(this).val().length;
                            if(len > 139){
                                $(this).val($(this).val().substring(0,140));
                            }
                            var num = 140 - len;
                            $("#word").text(num);
                        });
                    });
                </script>
            </div>
        </div>
        <div class="form-group clearfix">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label">文章排序:</label>
            <div class="col-sm-9 col-xs-12">
                  <input type="text" class="form-control" name="sort" id="sort" value="@if(!empty($result)){{$result->sort}}@else 0 @endif" placeholder="排序，数字越大越靠前">
            </div>
        </div>
        
        <input type="hidden" name="user_id" value="{{ Auth::user()->id }}">
        {!! csrf_field() !!}
        <input type="hidden" name="newsid" value="@if(!empty($result)){{ $result->id }}@endif">
        <div class="form-inline">
            <div class="form-group">
              <input type="hidden" name="status" value="1">
              <button type="button" class="btn btn-info" onclick="saveData('/admin/bbs/top','newsForm')">
                    <i class="icon-ok bigger-110"></i>
                    Submit
              </button>  
            </div>
                    
            <div class="form-group col-xs-offset-1">
                <button type="reset" class="btn">
                    <i class="icon-undo bigger-110"></i>
                    Reset
                </button>
            </div>
        </div>
    </div>
</form>

<script type="text/javascript">
<!--
$(function(){
	/***图片上传****/
	$("#uploadimg").uploadify({
	    'formData'     : {
	        'fileField':'upfile',
	        'app':'bbs',
	        '_token':'{{ csrf_token() }}'
	    },
	    "width"           : 120,
	    "height"          : 30,
	    "queueSizeLimit"  :1,
	    "swf"             : "{{ asset('/js/uploadify/uploadify.swf') }}",
	    "fileObjName"     : "upfile",
	    "buttonText"      : "上传图片",
	    "uploader"        : '/admin/upload/newsimage',
	    'removeTimeout'	  : 1,
	    'fileTypeExts'	  : '*.jpg; *.png; *.gif;',
	    'onUploadSuccess':function(file, data, response){
	    	var data = eval('(' + data + ')');
	        if (data.status == 'success') {

	            var html="<div style='width:90px; height:60px;float:left;'>"
	            	+"<img src='"+data.url+"' /><input type='hidden' name='thumb' value='"+data.url+"' />"
	            	+"</div>"
	            $('#imgbox').html(html);
	        }else{
	            alert(data.msg);
	            return false;
	        }

	    }

	});
	
});
//-->
</script>
@endsection
